package com.avo.ramcache.service;

import com.avo.ramcache.config.CachedEntityConfig;
import com.avo.ramcache.config.IEntity;
import com.avo.ramcache.persist.Persister;

import java.io.Serializable;
import java.util.Objects;

public interface EntityCacheService<PK extends Comparable<PK> & Serializable, T extends IEntity<PK>> extends ICacheService {

    T load(PK id);

    T unique(String name, Objects value);

    /**
     * 多服
     */
    T M2SUnique(int server, String name, Objects value);

    T loadOrCreate(PK id, EntityBuilder<PK, T> builder);

    T create(PK id, EntityBuilder<PK, T> builder);

    void writeBack(PK id, T entity);

    T remove(PK id);

    void clear(PK id);

    CacheFinder<PK, T> getFinder();

    CachedEntityConfig getEntityConfig();

    Persister getPersister();

    void stopServer(int server);

    void addElement(T current);

    T removeAndFresh(PK id);
}
